import scrapy
import json
from douban.MyDbUtil import MyDbUtil
from scrapy.crawler import CrawlerProcess
from scrapy.utils.project import get_project_settings


class XCFinalSpider(scrapy.Spider):
    name = 'xcfinal'

    def parse(self, response):
        mydb = MyDbUtil()
        rs = mydb.query_sql("select * from asp_area_index where area_Initials ='A'")
        thishref = "https://hotels.ctrip.com" + rs[0]['area_href']
        yield scrapy.Request(url=thishref,
                             callback=self.parse_page)

    def parse_page(self, response):
        print(json.loads(response.body.decode("utf-8")))


if __name__ == '__main__':
    process = CrawlerProcess(get_project_settings())
    process.crawl('xcfinal')
    process.start()
